package edu.ccut.saturn.studio.naviagtor.tester;

import java.io.File;

import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.jdt.internal.core.PackageFragment;

import edu.ccut.saturn.studio.naviagtor.SaturnDirectory;

/**
 * 表达式，判断.saturn文件中是否为"module"。 扩展点为
 * org.eclipse.core.expressions.propertyTesters。
 * 
 * @author alf 2008-9-1
 */
public class ModelSaturnTester extends PropertyTester {

	public boolean test(Object receiver, String property, Object[] args,
			Object expectedValue) {
		
		if (receiver instanceof PackageFragment) {
			String saturnPath = ((PackageFragment) receiver).getResource()
					.getLocation().toOSString()
					+ File.separator + ".saturn";
			
			SaturnDirectory saturnDirectory = SaturnDirectory
					.loadSaturnDirectory(new File(saturnPath));
			
			if (saturnDirectory != null) {
				if (SaturnDirectory.TYPE_MODEL.equals(saturnDirectory.getType())) {
					return true;
				}
			}
		}
		
		return false;
	}

}
